angular.module('starter.zjrService', [])


// 产品service
.factory('ZjrProduceService', function($http, $q) {
	
  return {
  	xsbData:function(){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/xsb/xsbData.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	countProduceToday:function() {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/countProduceToday.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//获取短贷数据
  	getProduceList:function(page,name,filter) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getProduceList.htm",
			params:{"page":page,"name":name,"filter":filter}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//获取长贷数据
  	getLongProduceList:function(page,name,filter) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getLongProduceList.htm",
			params:{"page":page,"name":name,"filter":filter}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//查询可用身价
  	getAvailableCreditValue:function() {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getAvailableCreditValue.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//保存短贷标
  	addProduce:function(produce) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/addProduce.htm",
			params:{"totalPrice":produce.totalPrice,
			"interestRates":produce.interestRates,"memo":produce.memo,"limitTime":produce.limitTime,
			"deadTime":produce.deadTime}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//保存新手贷标
  	addXsb:function(produce) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/xsb/addXsb.htm",
			params:{"totalPrice":produce.totalPrice,
			"interestRates":produce.interestRates,"memo":produce.memo,"limitTime":produce.limitTime,
			"deadTime":produce.deadTime}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//查询还款计划
  	getProducePayBackPlan:function(produce) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getProducePayBackPlan.htm",
			params:{"totalPrice":produce.totalPrice,"interestRates":produce.longInterestRates,
			"period":produce.period,"periodDays":produce.periodDays}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//保存长贷数据
  	addLongProduce:function(produce) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/addLongProduce.htm",
			params:{"totalPrice":produce.totalPrice,"interestRates":produce.longInterestRates,
			"period":produce.period,"periodDays":produce.periodDays,"memo":produce.memo,"limitTime":produce.limitTime}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//根据id查询标数据
  	getProduceById:function(produceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getProduceById.htm",
			params:{"produceId":produceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//根据id查询长贷数据
  	getProduceDetailById:function(longProduceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getProduceDetailById.htm",
			params:{"longProduceId":longProduceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  },
  	getMyProduceList:function(page){
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getMyProduceList.htm",
			params:{"page":page}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//查询短贷借入信息
  	getProduceListByUserId:function(status,page) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getProduceListByUserId.htm",
			params:{"status":status,"page":page}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//查询长贷借入信息
  	getLongProduceListByUserId:function(status,page) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getLongProduceListByUserId.htm",
			params:{"status":status,"page":page}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//短贷还款
  	savePayBack:function(produceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/savePayBack.htm",
			params:{"produceId":produceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//新手贷还款
  	savePayBackXsb:function(produceId) {
	  	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/xsb/xsbPayBack.htm",
			params:{"produceId":produceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  	});
	   return deferred.promise;
  	},
  	//我不借了
  	releaseProduce:function(produceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/releaseProduce.htm",
			params:{"produceId":produceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//根据产品查用户信息数据
  	getUserDetailByProduceId:function(produceId,flag) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getUserDetailByProduceId.htm",
			params:{"produceId":produceId,"flag":flag}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	getProduceCountToday:function() {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getProduceCountToday.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	getProduceListByFilter:function(page,filter) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/attention/myAttentionProduce.htm",
			params:{"page":page,"filter":filter}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	getProduceListBySortAndFilter:function(page,sort,filter) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getProduceList.htm",
			params:{"page":page,"filter":filter,"sort":sort}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	getCreditInfo:function() {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/produce/getCreditInfo.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	getAppLoanCollection:function(produceId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:"http://cuishou.credit-manage.com/getAppLoanCollection.htm",
			params:{"assigneId":produceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//长贷我不借了
  	releaseLongProduce:function(longProduceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/releaseLongProduce.htm",
			params:{"longProduceId":longProduceId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//获取最低长贷利率
  	getLevel:function() {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getLevel.htm"
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  });
	   return deferred.promise;
  	},
  	//长贷收益计划
  	getLoanPayBackPlan:function(principal,longProduceId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longLoan/getLoanPayBackPlan.htm",
			params:{"longProduceId":longProduceId,"principal":principal}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  	});
	   return deferred.promise;
  	},
  	  //获取户龄
  	getRegisterDayNumber:function(customerId) {
      	var deferred = $q.defer();
		$http({
			method:'post',
			url:userServerAdr+"/app/getRegisterDayNumber.htm",
			params:{"customerId":customerId}
		}).success(function (response) {
		  	deferred.resolve(response);
		}).error(function(data) {
	        deferred.reject();
	  	});
	   return deferred.promise;
  	}
  	
  };
  
})

//用户Service
.factory('UserService', function($http, $q) {
	
  return {
  	//查询用户信息
  	getUserById:function(){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getUserById.htm"
		}).success(function (response) {
			  deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//实名认证状态
  	getMnoAccountStatus:function(){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getMnoAccountStatus.htm"
		}).success(function (response) {
			  deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//转码
  	switchEncoding:function(pass,type){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/switchEncoding.htm",
			params:{"pass":pass,"type":type}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//实名认证
  	submitMno:function(dealCode){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:"http://www.credit-manage.com:8058/phone/juhe/saveJuHeMnoZJR.htm",
			params:{"dealCode":dealCode}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//获取统计信息
  	getUserCountById:function(){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getUserCountById.htm"
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//获取资金明细
  	getAccountDetailList:function(page){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getAccountDetailList.htm",
			params:{"page":page}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
	//用户资料信息
  	getUserInfoByUserId:function(customerId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getUserInfoByUserId.htm",
			params:{"customerId":customerId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	getTxwlAccountByUserId:function(){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getTxwlAccountByUserId.htm"
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	getZJRUserInfoByUserId:function(customerId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/getZJRUserInfoByUserId.htm",
			params:{"customerId":customerId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	}
  	 
  };
  
})

//投资Service
.factory('LoanService', function($http, $q) {
	
  return {
  	//保存短贷投资信息
  	saveLoan:function(produceId,loanMoney,reds){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/loan/saveLoan.htm",
			params:{"produceId":produceId,"loanMoney":loanMoney,"reds":reds}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//保存长贷投资信息
  	addLongLoan:function(produceId,principal,reds){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longLoan/addLongLoan.htm",
			params:{"longProduceId":produceId,"principal":principal,"reds":reds}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
 	},
 	//查询短贷借出数据
  	loanList:function(status,page){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/loan/loanList.htm",
			params:{"page":page,"status":status}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//查询长贷借出数据
  	getLongLoanListByUserId:function(status,page){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longLoan/getLongLoanListByUserId.htm",
			params:{"page":page,"status":status}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//查询借给他的人明细-短贷
  	loanDetailList:function(produceId,page){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/loanDetail/loanDetailList.htm",
			params:{"produceId":produceId,"page":page}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//查询借给他的人明细-长贷
  	longLoanDetailList:function(longProduceId,page){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/loanDetail/longLoanDetailList.htm",
			params:{"longProduceId":longProduceId,"page":page}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//借入分期还款列表
  	getLongProducePayBackList:function(longProduceId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getLongProducePayBackList.htm",
			params:{"longProduceId":longProduceId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//借出-长贷-已还清，还款明细
  	getAlreadyLoanPayBackById:function(longLoanRecordId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longloan/getAlreadyLoanPayBackById.htm",
			params:{"longLoanRecordId":longLoanRecordId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//当期还款
  	saveProducePayBack:function(longProducePayBackId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/saveProducePayBack.htm",
			params:{"longProducePayBackId":longProducePayBackId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//查询提前还款界面展示所需要的数据
  	getAdvanceByProduceId:function(longProduceId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/getAdvanceByProduceId.htm",
			params:{"longProduceId":longProduceId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//提前还款
  	saveAdvanceProducePayBack:function(longProduceId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/longProduce/saveAdvanceProducePayBack.htm",
			params:{"longProduceId":longProduceId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	},
  	//投资理财统计
  	getInvestment:function(customerId){
  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/user/getInvestment.htm",
				params:{"customerId":customerId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
  	},
  	//贷款负债(短贷)
  	getZJRUserInfoByUserId:function(customerId){
  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/user/getZJRUserInfoByUserId.htm",
				params:{"customerId":customerId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
  	},
  	//贷款负债(长贷)
  	getZJRLongUserInfoByUserId:function(customerId){
  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/user/getZJRLongUserInfoByUserId.htm",
				params:{"customerId":customerId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
  	},
  	//借出-当前-点进去的明细
  	getLongLoanPayBackById:function(longLoanRecordId){
  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/longLoan/getLongLoanPayBackById.htm",
				params:{"longLoanRecordId":longLoanRecordId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
  	},
  	//借出-已还清-点进去的明细
  	getAlreadyLoanPayBackById:function(longLoanRecordId){
  		var deferred = $q.defer();
			$http({
				method:'post',
				url:serverZjrAdr+"/app/longLoan/getAlreadyLoanPayBackById.htm",
				params:{"longLoanRecordId":longLoanRecordId}
				}).success(function (response) {
				  	deferred.resolve(response);
				}).error(function(data) {
			       deferred.reject();
				});
	   		return deferred.promise;
  	},
  	randomCj:function(produceId){
  		var deferred = $q.defer();
		$http({
			method:'post',
			url:serverZjrAdr+"/app/loan/randomCj.htm",
			params:{"produceId":produceId}
		}).success(function (response) {
			deferred.resolve(response);
		}).error(function(data) {
		    deferred.reject();
		});
		return deferred.promise;
  	}
  }
  
})




//文章Service
.factory('ArticleService', function($http, $q) {
  return {
	  //可用文章列表	  
		 articleList:function(page){
	      	var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/jtxy/list.htm",
					params:{"page":page}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
					deferred.reject();
			});
		   return deferred.promise;
		},
	     //文章详细	  
		 articleDetail:function(articelId){
	      	var deferred = $q.defer();
			$http({
					method:'post',
					url:serverZjrAdr+"/app/jtxy/articelDetail.htm",
					params:{"articelId":articelId}
				}).success(function (response) {
					deferred.resolve(response);
				}).error(function(data) {
					deferred.reject();
			});
		   return deferred.promise;
		}
  };
  
})

;
